<template>
	<view class="news-detail-page">
		<view style="font-size: 36rpx;font-weight: 600;margin: 20rpx 0;text-align: center;">{{formData.title}}</view>
		<view style="display: flex;text-align: center;margin: 20rpx 0;">
			<view style="text-align: left;flex:1;">直播时间：<uni-dateformat :threshold="[0, 0]" format="yyyy-MM-dd hh:mm" :date="formData.liveTime"></uni-dateformat></view>
			<view style="text-align: right;flex:1;">作者：{{formData.created_by}}</view>
		</view>
		<view style="margin: 20px 0;">
			<view v-html="formData.introduce"></view>
		</view>
		<view style="position: relative;" v-if="isNow">
			<button class="share" @click="toLiveBar" type="primary">看直播</button>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database();
	const dbCmd = db.command;
	import {
		filterArticles
	} from '@/utils/baseFn.js';
	export default {
		data() {
			return {
				formData: {
					title: '',
					created_date: '',
					created_by: '',
					introduce: ''
				},
				glabalData: {
					screenWidth: 0,
					screenHeight: 0
				},
				isNow: false
			}
		},
		onLoad(op) {
			this.getDetail(op.id)
		},
		onShow () {
			const info = wx.getSystemInfoSync()
			this.glabalData = {
			    screenWidth: info.screenWidth,
			    screenHeight: info.screenHeight
			}
		},
		created (op) {},
		mounted (op) {},
		methods: {
			getDetail(id) {
				uni.showLoading({
					mask: true
				})
				db.collection('live-bar-MGMT').doc(id).field(
					"title,introduce,annexId,liveTime,created_by").get().then((res) => {
					const data = res.result.data[0]
					if (data) {
						const file = data.annexId.split(',')
						data.introduce = filterArticles(data.introduce, this.glabalData)
						this.formData = data
						this.img = [{
							fileID: `${this.$baseImgUrl}${file[0]}`,
							url: `${this.$baseImgUrl}${file[0]}`,
							name: file[1]
						}]
						const nd = new Date()
						const ld = new Date(data.liveTime)
						const nds = `${nd.getFullYear()}${nd.getMonth()+1}${nd.getDate()}${nd.getHours()}`
						const lds = `${ld.getFullYear()}${ld.getMonth()+1}${ld.getDate()}${ld.getHours()+1}` // 直播时间+1小时
						this.isNow = nds <= lds ? true:false // 如果当前时间 <= 比赛
					}
				}).catch((err) => {
					uni.showModal({
						content: err.message || '请求服务失败',
						showCancel: false
					})
				}).finally(() => {
					uni.hideLoading()
				})
			},
			toLiveBar () {
				uni.navigateTo({
					url: `livePage`
				});
			}
		}
	}
</script>

<style>
	.news-detail-page {
		padding: 32rpx;
	}
	.fwb-img {
	  max-width: 100%;
	  margin: 10px 0;
	}
</style>
<style lang="scss">
</style>